<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>检测变量是否是一个标量</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.is-scalar" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">is_scalar</h1>
    <p class="verinfo">(PHP 4 &gt;= 4.0.5, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">is_scalar</span> &mdash; <span class="dc-title">
     检测变量是否是一个标量
    </span></p>

   </div>
   <div class="refsect1 unknown-unknown-unknown-unknown-unknown-unknown-unknown-seealsv" id="refsect1-function.is-scalar-unknown-unknown-unknown-unknown-unknown-unknown-unknown-seealsv">
    <h3 class="title">描述</h3>
     <div class="methodsynopsis dc-description">
      <span class="methodname"><strong>is_scalar</strong></span>
       ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$var</code></span>
      ) : <span class="type">bool</span></div>

    <p class="para rdfs-comment">
     如果给出的变量参数 <code class="parameter">var</code> 是一个标量，<span class="function"><strong>is_scalar()</strong></span>
     返回 <strong><code>TRUE</code></strong>，否则返回 <strong><code>FALSE</code></strong>。
    </p>
    <p class="para">
     标量变量是指那些包含了
     <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>、<span class="type"><a href="language.types.float.html" class="type float">float</a></span>、<span class="type"><a href="language.types.string.html" class="type string">string</a></span> 
     或 <span class="type"><a href="language.types.boolean.html" class="type boolean">boolean</a></span>的变量，而 
     <span class="type"><a href="language.types.array.html" class="type array">array</a></span>、<span class="type"><a href="language.types.object.html" class="type object">object</a></span> 和 <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span> 则不是标量。
     <div class="informalexample">
      <div class="example-contents">

<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">show_var</span><span style="color: #007700">(</span><span style="color: #0000BB">$var</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">is_scalar</span><span style="color: #007700">(</span><span style="color: #0000BB">$var</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$var</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$var</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">$pi&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">3.1416</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$proteins&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"hemoglobin"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"cytochrome&nbsp;c&nbsp;oxidase"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ferredoxin"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">show_var</span><span style="color: #007700">(</span><span style="color: #0000BB">$pi</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;打印：3.1416<br /><br /></span><span style="color: #0000BB">show_var</span><span style="color: #007700">(</span><span style="color: #0000BB">$proteins</span><span style="color: #007700">)<br /></span><span style="color: #FF8000">//&nbsp;打印：<br />//&nbsp;array(3)&nbsp;{<br />//&nbsp;&nbsp;&nbsp;[0]=&gt;<br />//&nbsp;&nbsp;&nbsp;string(10)&nbsp;"hemoglobin"<br />//&nbsp;&nbsp;&nbsp;[1]=&gt;<br />//&nbsp;&nbsp;&nbsp;string(20)&nbsp;"cytochrome&nbsp;c&nbsp;oxidase"<br />//&nbsp;&nbsp;&nbsp;[2]=&gt;<br />//&nbsp;&nbsp;&nbsp;string(10)&nbsp;"ferredoxin"<br />//&nbsp;}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
      </div>

     </div>
    </p>
    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <p class="para">
      尽管当前的 <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span> 类型是居于整数的，但 
      <span class="function"><strong>is_scalar()</strong></span> 不会把它们当作是标量，因为资源是抽象数据类型。不能依赖于执行细节，因为它可能会改变。
     </p>
    </p></blockquote>
    <p class="para">
     参见 <span class="function"><a href="is_bool.html" class="function">is_bool()</a></span>、<span class="function"><a href="is_numeric.html" class="function">is_numeric()</a></span>、<span class="function"><a href="is_float.html" class="function">is_float()</a></span>、<span class="function"><a href="is_int.html" class="function">is_int()</a></span>、<span class="function"><a href="is_real.html" class="function">is_real()</a></span>、<span class="function"><a href="is_string.html" class="function">is_string()</a></span>、<span class="function"><a href="is_object.html" class="function">is_object()</a></span>、<span class="function"><a href="is_array.html" class="function">is_array()</a></span>
     和 <span class="function"><a href="is_integer.html" class="function">is_integer()</a></span>。
    </p>
   </div>

  </div></div></div></body></html>